﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Domain.Config;
using Infrastructure.Error;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace FacadeApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ConfigController : ControllerBase
    {
        public ILogger<ConfigController> _logger { get; set; }
        [HttpGet]
        public ActionResult<List<Domain.Model.RewardListAggregate>> GetPageConfig(int type)
        {
            string ipaddress = this.HttpContext.Connection.RemoteIpAddress.ToString();

            try
            {
                Dictionary<string, string> map = new Dictionary<string, string>();

                var key = "page.showAward";
                map.Add(key, SystemConfig.GetConfigByTime<string>("系统配置", key, TimeSpan.FromDays(1)));
                key = "page.showRecommend";
                map.Add(key, SystemConfig.GetConfigByTime<string>("系统配置", key, TimeSpan.FromDays(1)));

                return this.Success(map, hasMore: false);
            }
            catch (BizException ex)
            {
                return this.FailResult(ex.data, ex.Message);
            }
            catch (Exception ex)
            {
                _logger.LogException(ex);
                return this.FailResult(null, "系统繁忙，请稍后重试!");
            }
        }
    }
}
